package com.gm.wholesale.module.settlement.ui.main;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;

import com.gm.commonlib.base.baseui.baseFragment.BaseFragment;
import com.gm.wholesale.R;

public class AccountMainFragment extends BaseFragment {
    private AccountCustormListFragment custormListFragment;
    private AccountContentFragment contentFragment;


    @Override
    protected void onCreateContentBody(ViewGroup parent) {
        super.onCreateContentBody(parent);
        LayoutInflater.from(context).inflate(R.layout.fragment_to_account_main, parent);
        custormListFragment = (AccountCustormListFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.accountCustormListFragment);
        custormListFragment.setIsGetData(true);
        contentFragment = (AccountContentFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.accountContentFragment);

    }

    private void removeFragment(Fragment fragment) {
        getActivity().getSupportFragmentManager().beginTransaction().remove(fragment).commitAllowingStateLoss();
    }

    public void removeFragment() {
        if (custormListFragment != null) {
            removeFragment(custormListFragment);
        }
        if (contentFragment != null) {
            removeFragment(contentFragment);
        }

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        //todo 必须销毁它嵌套的相关fragment，不然下次添加会报错
        // todo因为子fragment没有销毁，还依附在当前fragment，不能再次被添加
        removeFragment(); //移除嵌套的fragment

    }
}
